package com.suirich.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.suirich.bean.JobReference;
import com.suirich.common.Page;
import com.suirich.dao.JobReferenceDao;

@Repository
public class JobReferenceDaoImpl extends GenericDaoHibernateImpl<JobReference, Long> implements JobReferenceDao {
	public JobReferenceDaoImpl() {
		super(JobReference.class);
	}

	@SuppressWarnings("unchecked")
	public List<JobReference> getJobReferenceList(Page page) {
		String hql = "from JobReference j order by j.updateDate desc,j.createDate desc";
		
		Query query = this.getCurrentSession().createQuery(hql);

        if (page != null) {
            query.setFirstResult((page.getCurrentPage() - 1)
                    * page.getPerPageSize());
            query.setMaxResults(page.getPerPageSize());
        }
        
		return (List<JobReference>)query.list();
	}

	public Long getJobReferenceListCount() {
		String hql = "select count(j.id) from JobReference j";
		
		Query query = this.getCurrentSession().createQuery(hql);
		
		return (Long)query.uniqueResult();
	}
}
